#SingleInstance Force
#Persistent
#NoTrayIcon
SetBatchLines,-1
WorkerWstate=0
HookProcAdr := RegisterCallback( "HookProc", "F" )
hWinEventHook := SetWinEventHook( 0x3, 0x3, 0, HookProcAdr, 0, 0, 0 )
OnExit, HandleExit
SetTimer, UpdateRM, 10
Return



UpdateRM:
if(WorkerWstate=1)
{

   WinGet, active_id, ID, A
   WinGetClass,class,ahk_id %active_id%
   if(class="WorkerW")
   {
      WorkerWState=0
      ;tooltip, state: %WorkerWstate%
      CustomColor = EEAA99
      WinGet, active_id, ID, A

      ;sleep,100
      gui -caption
      Gui, Color, %CustomColor%
      WinSet, TransColor, %CustomColor% 0
      WinGet, active_id, ID, A
      Gui, Show, x0 y0  ; NoActivate avoids deactivating the currently active window.
      Gui, Destroy
      WinGetClass,class,ahk_id %active_id%
      if(class<>"WorkerW") {
         WinActivate,ahk_id %active_id%
      }

   }
}
return




HookProc( hWinEventHook, Event, hWnd, idObject, idChild, dwEventThread, dwmsEventTime )
{
   if (Event=0x3)   { ;foreground
         Wingetclass,namClass,ahk_id %hWnd%
         if(namClass="WorkerW") {
            global WorkerWState:=1
         }
   }


}

SetWinEventHook(eventMin, eventMax, hmodWinEventProc, lpfnWinEventProc, idProcess, idThread, dwFlags)
{
   DllCall("CoInitialize", Uint, 0)
   return DllCall("SetWinEventHook"
   , Uint,eventMin
   , Uint,eventMax
   , Uint,hmodWinEventProc
   , Uint,lpfnWinEventProc
   , Uint,idProcess
   , Uint,idThread
   , Uint,dwFlags)
}

UnhookWinEvent()
{
   Global
   DllCall( "UnhookWinEvent", Uint,hWinEventHook )
   DllCall( "GlobalFree", UInt,&HookProcAdr ) ; free up allocated memory for RegisterCallback
}

#z::
goto HandleExit
ExitApp

HandleExit:
UnhookWinEvent()
ExitApp
Return